#ifndef _Ape__EventModel_EventCallback_h
#define _Ape__EventModel_EventCallback_h

#include <Ape/Object.h>
#include <Ape/EventModel/Callback.h>
#include <Ape/EventModel/EventArgs.h>

namespace Ape {
	namespace EventModel {
	
		class EventCallback_Base : public Callback {
			TYPE_NAME ("Ape::EventModel::EventCallback_Base")
		public:
			EventCallback_Base (Object* object);
			virtual void operator () (EventArgs& evt) const = 0;
		};
		
		template<class Callee_t>
		class EventCallback : public EventCallback_Base {
			TYPE_NAME ("Ape::EventModel::EventCallback<Callee_t>")
		public:
			typedef void (Callee_t::*Method_t) (EventArgs&);
		private:
			mutable Callee_t* m_Object;
			Method_t m_Method;
		public:
			EventCallback (Callee_t* object, Method_t method)
					: EventCallback_Base (object),
					m_Object (object),
					m_Method (method)
			{}
			
			virtual ~EventCallback() {}
			
			virtual void operator () (EventArgs& evt) const {
				(m_Object->*m_Method) (evt);
			}
		};
		
#define Delegate(Callee_t, pCallee, MethodName) \
	new Ape::EventModel::EventCallback< Callee_t >( pCallee, &Callee_t::MethodName)
		
	}
}

#endif // _Ape__EventModel_EventCallback_h
